package com.tanhua.server.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.model.vo.ContactVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import com.tanhua.server.service.MessagesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessagesController {
    @Autowired
    private MessagesService messagesService;

    @GetMapping("/userinfo")
    public ResponseEntity userInfo(String huanxinId){
        UserInfoVo userInfoVo=messagesService.findUserInfoByHuanxin(huanxinId);
        return ResponseEntity.ok(userInfoVo);

    }

    //加好友
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map map){
        String userId =map.get("userId").toString();
        Long id = Long.valueOf(userId);
        messagesService.contacts(id);
        return ResponseEntity.ok(null);
    }

    @GetMapping("/contacts")
    public ResponseEntity list(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer pagesize,
                               String keyword){
        PageResult pr=messagesService.list(page,pagesize,keyword);
        return ResponseEntity.ok(pr);
    }

}
